import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/scores',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Scores',
        component: () => import('@/views/scores/index'),
        meta: { title: '成绩表', icon: 'el-icon-s-data' }
      },
    ]
  },
  {
    path: '/course',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Course',
        component: () => import('@/views/course/index'),
        meta: { title: '课程表', icon: 'el-icon-s-management' }
      },
    ]
  },
  {
    path: '/semester',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'semester',
        component: () => import('@/views/semester/index'),
        meta: { title: '学期', icon: 'el-icon-s-marketing' }
      },
    ]
  },

  {
    path: '/category',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Category',
        component: () => import('@/views/category/index'),
        meta: { title: '课程类别', icon: 'el-icon-menu' }
      },
    ]
  },

  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: { title: '学生', icon: 'el-icon-s-custom' }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '管理员', icon: 'el-icon-user-solid' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]



const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})



const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher 
}

export default router
